using MicroMsg.Manager;
using System;
namespace MicroMsg.Plugin
{
	public class PluginMetaStorage
	{
		private const string TAG = "PluginMetaStorage";
		private static PluginMetaMap mPluginMetaMap;
		public static bool restoreMetaInfo(PluginBase plug)
		{
			if (PluginMetaStorage.mPluginMetaMap == null || plug == null)
			{
				return false;
			}
			string text = plug.mName + plug.mID;
			if (!PluginMetaStorage.mPluginMetaMap.mapPluginMetaInfo.ContainsKey(text))
			{
				return false;
			}
			PluginMetaInfo plugMeta = PluginMetaStorage.mPluginMetaMap.mapPluginMetaInfo.get_Item(text);
			plug.mMetaInfo.copyFrom(plugMeta);
			return true;
		}
		public static bool updateMetaInfo(PluginBase plug)
		{
			if (PluginMetaStorage.mPluginMetaMap != null && PluginBase.isValidPlugin(plug))
			{
				string text = plug.mName + plug.mID;
				if (!PluginMetaStorage.mPluginMetaMap.mapPluginMetaInfo.ContainsKey(text))
				{
					PluginMetaInfo pluginMetaInfo = new PluginMetaInfo();
					pluginMetaInfo.copyFrom(plug.mMetaInfo);
					PluginMetaStorage.mPluginMetaMap.mapPluginMetaInfo.Add(text, pluginMetaInfo);
				}
				else
				{
					PluginMetaInfo pluginMetaInfo2 = PluginMetaStorage.mPluginMetaMap.mapPluginMetaInfo.get_Item(text);
					pluginMetaInfo2.copyFrom(plug.mMetaInfo);
				}
				PluginMetaStorage.flushMetaToXML();
				return true;
			}
			return true;
		}
		public static void loadMetaFromXML()
		{
			PluginMetaStorage.mPluginMetaMap = ConfigMgr.read<PluginMetaMap>();
			if (PluginMetaStorage.mPluginMetaMap == null)
			{
				PluginMetaStorage.mPluginMetaMap = new PluginMetaMap();
			}
		}
		public static void flushMetaToXML()
		{
			ConfigMgr.write<PluginMetaMap>(PluginMetaStorage.mPluginMetaMap);
		}
	}
}
